package ch03.demo.factory;

import ch03.demo.dao.NewDao;
import ch03.demo.dao.impl.NewsDaoMySqlImpl;
import ch03.demo.dao.impl.NewsDaoOracleImpl;
import ch03.demo.dao.impl.NewsDaoRedisImpl;

public class SimpleDaoFactory {
    /**
     * 创建NewsDao实例的工厂类
     * @return
     */
    public static NewDao getInstance(String key){

        //   return new NewDaoImpl();
        switch (key)
        {
            case "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库:"+key+",DAO获取失败!");
        }
    }
}

